<template>
  <el-dialog title="销项发票明细" :visible.sync="dialogVisible" width="1200px" :close-on-click-modal="false"
    :modal-append-to-body="false" v-drag2anywhere>
    <div style="height: 400px; overflow-y: auto;">
    <el-table :data="tableData" border>
      <el-table-column label="序号" type="index" align="center"></el-table-column>
      <el-table-column label="税收分类及编码" prop="taxname">
        <template v-slot="scope">
          {{scope.row.taxname}}({{scope.row.taxcode}})
         </template>
      </el-table-column>
      <el-table-column label="产品或服务名称" prop="title" width="140px"></el-table-column>
      <el-table-column label="单位" prop="unit" width="60px" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column label="数量" prop="count" width="80px" align="center"></el-table-column>
      <el-table-column label="单价" prop="price" width="110px" align="center"></el-table-column>
      <el-table-column label="非税金额" prop="total" width="100px" align="center"></el-table-column>
      <el-table-column label="税率" prop="rate" width="100px" align="center">
        <template v-slot="scope">
          {{scope.row.rate*100}}%
        </template>
      </el-table-column>
      <el-table-column label="税额" prop="tax" width="95px" align="center"></el-table-column>
      <el-table-column label="总额" prop="sum" width="100px"align="center"></el-table-column>
      <el-table-column label="进项状态" prop="bind_buyticket_status" width="80px" align="center">
        <template v-slot="scope">
          <span v-if="scope.row.bind_buyticket_status==0" style="color: coral;">不完整</span>
          <span v-if="scope.row.bind_buyticket_status==1" style="color: forestgreen;">完整</span>
        </template>
      </el-table-column>
    </el-table>
     </div>
    <div style="text-align: right; line-height: 35px;">
      <span style="margin-left: 20px;">非税金额:{{parseFloat(total).toFixed(2)}}</span>
      <span style="margin-left: 20px;">税额:{{parseFloat(tax).toFixed(2)}}</span>
      <span style="margin-left: 20px;">含税总额:{{parseFloat(sum).toFixed(2)}}</span>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" size="medium" @click="dialogVisible=false">确定</el-button>
    </div>
   
  </el-dialog>
</template>

<script>
  export default {
    data(){
      return {
         index:-1,
         saleid:-1,
         dialogVisible:false,
         tableData:[],
         sum:0,
         tax:0,
         total:0,
      }
    },
    methods:{
      init(index,data){
        console.log(data);
         this.index=index;
         this.saleid=data.id;
         this.loadDetailList();
      },
      loadDetailList(){
        const params={
           id:this.saleid
        }

        this.axios.post("api/admin/saleticket/detaillist",params).then(res=>{
            if(res.status==200 && res.data.code){
              this.tableData=res.data.list;
              this.sum=0;
              this.total=0;
              this.tax=0;
              this.tableData.map((item)=>{
                  this.sum+=parseFloat(item.sum);
                  this.total+=parseFloat(item.total);
                  this.tax+=parseFloat(item.tax);
              })
            }
        })
      }
    }
  }
</script>

<style>
</style>
